IF EXISTS (SELECT * FROM sysobjects WHERE type = 'U' AND name = 'USER2EDUCATION')
BEGIN
    DROP TABLE [dbo].[USER2EDUCATION]
END

GO

CREATE TABLE [dbo].[USER2EDUCATION] ( 
	[ID]			INT IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
	[USER_ID]       INT         NOT NULL,
    [MODULE_ID]     INT         NOT NULL,
    [STATUS]        VARCHAR(10) NOT NULL CONSTRAINT [CK_USER2EDUCATION_STATUS]
            CHECK NOT FOR REPLICATION (STATUS IN ('Assigne', 'Approve', 'Start', 'Finish', 'Success', 'Cancel', 'Failure', 'Reopen'))
            DEFAULT 'Assignment',
	[MARK]        	VARCHAR(10)

    CONSTRAINT [PK_USER2EDUCATION_ID] PRIMARY KEY CLUSTERED ( 
        [ID] 
    ) ON [PRIMARY],
    
    CONSTRAINT [FK_USER2EDUCATION_USER_ID] FOREIGN KEY ( 
        [USER_ID]
    ) REFERENCES [dbo].[USER] (
        [ID]
    ),
    
    CONSTRAINT [FK_USER2EDUCATION_MODULE_ID] FOREIGN KEY ( 
        [MODULE_ID]
    ) REFERENCES [dbo].[EDUCATION_MODULE] (
        [ID]
    )
    
) ON [PRIMARY] 

CREATE INDEX [IDX_USER2EDUCATION_USER_ID_MODULE_ID] on [dbo].[USER2EDUCATION] ([USER_ID],[MODULE_ID]) 

GO